using System.Collections.Generic;
using AndyPike.Unfuddle.Contracts;
using AndyPike.Unfuddle.Entities.Projects;

namespace AndyPike.Unfuddle.Commands.Projects
{
    /// <summary>
    /// Provides a command for returning all projects for a given account
    /// </summary>
    public class FindAllProjects : IUnfuddleFindCommand<List<Project>>
    {
        /// <summary>
        /// Queries the Unfuddle server for all projects for a given account
        /// </summary>
        /// <param name="service">The Unfuddle service to use when executing the command</param>
        /// <returns>Returns a list of projects for the given account</returns>
        public List<Project> Execute(IUnfuddleService service)
        {
            GuardAgainst.ArgumentNull(service, "service");

            string url = service.BuildUrl("projects");
            var collection = service.InvokeRequest<ProjectsCollection>(url);
            return collection.Projects;
        }
    }
}